package service

import (
	"context"
	"github.com/GUOSAITONG/MyConfig/pkg"
	__ "hospital-srv/basic/proto"
	"hospital-srv/handler/dao"
	"math/rand"
	"strconv"
)

type Serve struct {
	__.UnimplementedHospitalServer
}

// 发送短信验证码
func (s *Serve) SendSms(_ context.Context, in *__.SendSmsReq) (*__.SendSmsResp, error) {
	intn := rand.Intn(9000) + 1000
	xian := pkg.HuYiWuXian{}
	_, err := xian.Send(in.Mobile, strconv.Itoa(intn))
	if err != nil {
		return nil, err
	}
	return &__.SendSmsResp{
		Intn:    int64(intn),
		Message: "发送短信成功",
	}, nil
}

// 支付宝支付
func (s *Serve) Alipay(_ context.Context, in *__.AlipayReq) (*__.AlipayResp, error) {
	err, pay := dao.AliPay(in)
	if err != nil {
		return nil, err
	}
	return &__.AlipayResp{
		PayURL: pay,
	}, nil
}
